﻿using Star_Helper;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        test();
        dataFunc d = new dataFunc();  
        if (!IsPostBack)
        { 
            string sx = Request.Form["login"];
            if (sx != null && sx != "undefined")//
            {
                switch (sx)
                {
                    case "zhuce":
                        register(Request.Form["name"], Request.Form["mima"]);
                        break;
                    case "denglu":
                        
                        isLogin(Request.Form["name"], Request.Form["mima"]);
                        break;
                    default:

                        break;
                }          
            }
            else
            {/*
                string s = Request.QueryString["name"];
                if (Request.QueryString["name"] != null)//get
                {
                    Response.Write(s);
                    Response.End();
                }*/
            }

        }
    }

    public void test()//不存在数据库就生成数据库并一些测试值
    {
        DoDB b = new DoDB();
        if (!b.hasSqlTable("TSyonghu"))
        {
            b.initSqlTable();
            b.initTestValue();
            b.addYonghu("a", "123");//测试账号

        }

    }

    public void isLogin(string sx, string sx2)
    {
        DoDB b = new DoDB();
        if (b.hasYonghu(sx)){
            if (b.hasLogin(sx, sx2))
            {
                //Response.Write("<script>alert(\"登陆成功\")</script>");
                Response.Write(new DoDom().creaW());
                Response.End();
            }
            else
            {
                Response.Write("<script>alert(\"密码错误\")</script>");
            }
        }
        else
        {
            Response.Write("<script>alert(\"账号错误\")</script>");
        }

    }

    /// <summary>
    /// 注册
    /// </summary>
    /// <param name="sx"></param>
    /// <param name="sx2"></param>
    public void register(string sx, string sx2)
    {
        DoDB b = new DoDB();
        if (b.hasYonghu(sx))
        {
            Response.Write("<script>alert(\"账号已存在\")</script>");
        }
        else
        {
            b.addYonghu(sx, sx2);
            //Response.Write("<script>alert(\"注册成功\")</script>");
            Response.Write(new DoDom().creaW());
            Response.End();
        }
    }


}